package app.auto.runner.func;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import app.auto.runner.base.ActivityStack;
import app.auto.runner.base.RRes;
import app.auto.runner.base.action.ParamType;
import app.auto.runner.base.framework.Init;
import app.auto.runner.base.task.StringFormatTask;
import app.auto.runner.base.utility.ToastUtil;

/**
 * Created by admin on 2017/9/3.
 */
@ParamType(type = "ActivitySimpleName simplename;R.id.xxx id", desc = "点击界面指定视图组件")
public class Checknotnull extends StringFormatTask {


    @Override
    public Object run(View view, String... params) {
        try {
            Class clz = Class.forName(Init.bigContext.getPackageName() + ".Activity." + params[0].toString());
            TextView tv = ((TextView) ActivityStack.getInstance().findActivityByClass(clz).findViewById(RRes.get("R.id." + params[0].toString()).getAndroidValue()));
            if (TextUtils.isEmpty(tv.getText())) {
                ToastUtil.live(ActivityStack.getInstance().findActivityByClass(clz)).toast(params[1]);
                return true;
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return false;
    }

    public static boolean check(TextView v) {
        return TextUtils.isEmpty(v.getText());

    }
}
